package simpleFactory;

import simpleFactory.pizza.Pizza;

import java.util.Scanner;

/**
 * @author : DuJiabao
 * @Date : 2021/3/1 20:11
 * @Project : design-pattern
 * @File : null.java
 * @Desc :
 */
public class OrderPizza {
  private SimpleFactory simpleFactory;

  public OrderPizza(SimpleFactory simpleFactory) {
    this.simpleFactory = simpleFactory;
  }

  public void manage(Scanner scan) {
    // 获取需要
    while (scan.hasNextLine()) {
      String s = scan.nextLine();
      Pizza pizza = simpleFactory.createPizza(s);
      if (pizza != null) {
        pizza.prepare();
        pizza.bake();
        pizza.cut();
        pizza.box();
      } else {
        System.out.println("订购披萨失败");
        break;
      }
    }
  }

  public static void main(String[] args) {
    OrderPizza orderPizza = new OrderPizza(new SimpleFactory());
    orderPizza.manage(new Scanner(System.in));
  }
}
